-
Notifications
You must be signed in to change notification settings - Fork 67
Introduce SwiftFormat #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| expect(try encoder.encode(Numbers(uint64: 4294967295))).to(equal(["uint64": .int64(4294967295)])) | ||
| expect(try encoder.encode(Numbers(uint: 4294967295))).to(equal(["uint": .int64(4294967295)])) | ||
| expect(try encoder.encode(Numbers(uint64: 4_294_967_295))).to(equal(["uint64": .int64(4_294_967_295)])) | ||
| expect(try encoder.encode(Numbers(uint: 4_294_967_295))).to(equal(["uint": .int64(4_294_967_295)])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding underscores in large number literals is another interesting change that's on by default. Let me know what you guys think about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it 👍
kmahar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally lgtm.
in general, I found that this approach to wrapping produces far more readable and condensed code than only doing the "after-first" option
what does after first look like?
| --wraparguments "before-first" | ||
|
|
||
| # if x == 1 vs if 1 == x | ||
| --disable yodaConditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one seems reasonable to leave on to me, 1 == x looks kinda weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yodaConditions actually enforces the 1 == x, so it's being disabled here; I agree, look weird it does. It's called a "yoda" condition because if read it sounds like you're speaking like Yoda from star wars...lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmao well... good for star wars fans I suppose
patrickfreed
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first code snippets in the PR description are examples of the "after-first" way. "after-first" and "before-first" mean "line break before/after first parameter"
| --wraparguments "before-first" | ||
|
|
||
| # if x == 1 vs if 1 == x | ||
| --disable yodaConditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yodaConditions actually enforces the 1 == x, so it's being disabled here; I agree, look weird it does. It's called a "yoda" condition because if read it sounds like you're speaking like Yoda from star wars...lol
This PR runs SwiftFormat on the driver and adds it as part of our linting task.
In general, I tried to emulate our swiftlint config as much as possible so that this formatter would help us enforce existing rules rather than making up new ones. The one notable exception to that is the wrapArguments rule, which I've standardized to "before-first". I don't think there is a right answer here as to which option is better, but I do think that selecting any option for consistency is the right idea (as @Utagai said long ago). The majority of the diff from this PR is due to this rule.
e.g.
becomes
In general, I found that this approach to wrapping produces far more readable and condensed code than only doing the "after-first" option, so I went with it.
Another thing to note is that this rule only applies to how we format multiline arguments; it doesn't decide when we do it.
e.g. the following will be untouched by the formatter:
This means that not all output produced by the formatter will pass
swiftlintdue to line length issues, so manual line breakage may be necessary. The formatter will make sure that the way the lines are broken is fixed up, though.Why not
swift-format?There is an official formatter being worked on by Apple called
swift-format. I decided not to use it for this because it supports a very small number of rules compared to SwiftFormat. I think that long term, it may make sense to start using the official formatter once it becomes more mature.